package com.starlink.controller;

import com.starlink.common.WebResponse;
import com.starlink.model.vo.AddressTreeVO;
import com.starlink.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/common")
@Api(value = "通用模块", tags = {"通用模块"})
public class CommonController {
    @Autowired
    private CommonService commonService;

    @ApiOperation("查询所有省")
    @GetMapping("/queryAllProvince")
    public WebResponse<List<Map<String,String>>> queryAllProvince() {
        return WebResponse.build(commonService.queryAllProvince());
    }

    @ApiOperation("通过code查询市")
    @GetMapping("/queryCityByCode/{code}")
    public WebResponse<List<Map<String,String>>> queryCityByCode(@PathVariable("code")String code) {
        return WebResponse.build(commonService.queryCityByCode(code));
    }

    @ApiOperation("通过code查询区")
    @GetMapping("/queryAreaByCode/{code}")
    public WebResponse<List<Map<String,String>>> queryAreaByCode(@PathVariable("code")String code) {
        return WebResponse.build(commonService.queryAreaByCode(code));
    }

    @ApiOperation("查询地址树")
    @GetMapping("/queryAddressTree")
    public WebResponse<List<AddressTreeVO>> queryAddressTree() {
        return WebResponse.build(commonService.queryAddressTree());
    }

}
